// pages/xianguapaiyouliquan/xianguapaiyouliquan.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img: [],
    flag: true, //设置节流
  },


  huye(e) {
    console.log(e.currentTarget.dataset.index);
    

    wx.navigateTo({
      url: '../../pages/xianguapaiyoulihuodongye/xianguapaiyoulihuodongye?data=' + e.currentTarget.dataset.index,
    })

  },


  quchoujiang(e) {
    console.log(e.currentTarget.dataset.item.USER_ASSETS_IDCARD);
    

    wx.navigateTo({
      url: '../../pages/akfennanchoujiang/akfennanchoujiang?data=' + e.currentTarget.dataset.item.USER_ASSETS_IDCARD,
    })

  },





  tankuang(e) {

    console.log(e);
    console.log(e.currentTarget.dataset.item.PRIZE_ID);

    if (e.currentTarget.dataset.item.VALID == 2) {

      wx.showModal({
        title: '温馨提示',
        content: '激活请咨询' + this.data.L4name,
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })

    } else {

      wx.request({
        url: app.globalData.interface+'/xianPost/API_6045_xianGuaPaiYouLiUpdate',
        method: 'POST',
        data: {
          PRIZE_ID: e.currentTarget.dataset.item.PRIZE_ID,
          OPEN_ID: app.globalData.openid, //用户OPEN_ID
          session_key: app.globalData.session_key,
          OPEN_UUID: app.globalData.jiami,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {

          console.log(res);

          let thia = this

          if (res.data.result == 'success') {
            wx.showModal({
              title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                  thia.chaxunbaoming()
                } else if (res.cancel) {
                  console.log('用户点击取消')
                  thia.chaxunbaoming()
                }
              }
            })
          } else {


            wx.showModal({
              title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }
        }
      })
    }
  },




  lingqu(e) {
    if (this.data.flag) {
      this.data.flag = false

      console.log(e);
      wx.request({
        url: app.globalData.interface+'/xianPost/API_6051_xianGuaPaiYouLiGiftRaffle ',
        method: 'POST',
        data: {
          PRIZE_ID: e.currentTarget.dataset.item.PRIZE_ID,
          USER_ASSETS_IDCARD: e.currentTarget.dataset.item.USER_ASSETS_IDCARD,
          OPEN_ID: app.globalData.openid, //用户OPEN_ID
          session_key: app.globalData.session_key,
          OPEN_UUID: app.globalData.jiami,

        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res);
          let thia = this
          console.log(res.data.data.Prize);
          if (res.data.result == 'error') {
            wx.showModal({
              title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                  thia.chaxunbaoming()
                } else if (res.cancel) {
                  console.log('用户点击取消')
                  thia.chaxunbaoming()
                }
              }
            })

          } else {
            wx.showModal({
              title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                  thia.chaxunbaoming()
                } else if (res.cancel) {
                  console.log('用户点击取消')
                  thia.chaxunbaoming()
                }
              }
            })

          }
        }
      })
      setTimeout(() => {
        this.data.flag = true
      }, 5000)
    }

  },







  chaxunbaoming() {

    wx.request({
      url: app.globalData.interface+'/xianPost/API_6043_xianGuaPaiYouLiSelect',
      method: 'POST',
      data: {

        OPEN_ID: app.globalData.openid, //用户OPEN_ID
        session_key: app.globalData.session_key,
        OPEN_UUID: app.globalData.jiami,

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);

        console.log(res.data.data.Prize);
        if (res.data.result == 'error') {
          console.log('未报名');
        } else {
          this.setData({
            img: res.data.data.Prize,
            L4name: res.data.data.L4name,
          })

        }
      }
    })


  },






  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.chaxunbaoming()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})